import * as types from './mutations_types';
import simplified_chinese from '../assets/js/international/simplified_chinese.js';
import traditional_chinese from '../assets/js/international/traditional_chinese.js';
import english from '../assets/js/international/english.js';

let hideToast = (time, callback) => {
	setTimeout(function() {
		callback();
	}, time);
};

// 控制toast的显示和自动隐藏
export const toastToggle = ({ commit }, toastSetting) => {
	let time = toastSetting.time || 1500;
	let isToasting = toastSetting.isToasting,
		onHidden = toastSetting.onHidden;
	commit(types.SET_TOAST, {
		info: toastSetting.info,
		icon: toastSetting.icon,
		time: time,
		onHidden: onHidden
	});
	commit(types.TOAST_TOGGLE, isToasting);
	if (isToasting) {
		hideToast(time, () => {
			commit(types.TOAST_TOGGLE, false);
			if (onHidden) {
				onHidden();
			}
		});
	}
};
// 保存表格页面设置
export const setUserSetting = ({ commit }, params) => {
	return new Promise((resolve, reject) => {
		Vue.http.post('/mgr/v1/system/cache', params).then(
			response => {
				let res = response.data;
				let resultCode = res.resultCode;
				let data = res.data;
				if (resultCode == 0) {
					if (data) {
						resolve(data);
					} else {
						resolve(success);
					}
				} else {
					reject(res);
				}
			},
			response => {
				reject(response);
			}
		);
	});
};
